import React, { useState, useEffect } from 'react'

export default function App() {
  const [count, setCount] = useState(10)
  useEffect(() => {
    const timer = setInterval(() => {
      console.log('~~~~~~')
      setCount((count) => count - 1)
    }, 1000)
    return () => {
      // 在清理函数里面，清理定时器，组件销毁必然会执行清理函数
      clearInterval(timer)
    }
  }, [])
  return <div>{count}</div>
}
